/*
* $Id: UpdateFHOperation.cpp 169 2010-10-16 17:46:54Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
#include "Common/include.h"
#include "UpdateFHOperation.h"
#include "../SqlBinder.h"
#include "../Tables/TableNames.h"

CUpdateFHOperation::CUpdateFHOperation(){}
CUpdateFHOperation::~CUpdateFHOperation(){}

CUpdateFHOperation::content::content(){
	Clear();
}

void CUpdateFHOperation::content::Clear(){
	s_nIdFamily = 0;
	s_nIdNewFamily = 0;
	s_nId = 0;
}

void CUpdateFHOperation::UpdateValue(IDatabase* pDatabase){
	CSqlBinder binder;
	std::tstring strRequest(_T("UPDATE "));
	binder.SetValue(0, m_content.s_nIdNewFamily);
	if(m_content.s_nId){
		binder.SetRequest(strRequest + HOUSINGS_TABLE_NAME + _T(" SET id_family=? WHERE id_housing=?"));
		binder.SetValue(1, m_content.s_nId);
	}else if(m_content.s_nIdFamily){
		binder.SetRequest(strRequest + HOUSINGS_TABLE_NAME + _T(" SET id_family=? WHERE id_family=?"));
		binder.SetValue(1, m_content.s_nIdFamily);
	}
	pDatabase->ExecRequest(binder.GetRequest());
	m_content.Clear();
}
